[Java] - Problem having my main thread sleeping

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-18T18:36:47Z Indexed on 2010/04/18 18:43 UTC
Read the original article Hit count: 331

Filed under:
|

I'm in a Java class and our assignment is to let us explore threads in Java. So far so good except for this one this one problem. And I believe that could be because of my lack of understanding how Java threads work at the moment.

I have the main thread of execution which spawns new threads. In the main thread of execution in main() I am calling Thread.sleep(). When I do I get an Unhandled exception type InterruptedException. I am unsure of why I am getting this? I thought this was because I needed a reference to the main thread so I went ahead and made a reference to it via Thread.currentThread().

Is this not the way to have the thread sleep? What I need to do is have the main thread wait/sleep/delay till it does it required work again. Any help would be much appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about threading